package com.kws.tool.util;

import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;

import java.util.List;
import java.util.Map;

/**
 * @author : zhangbenting
 * @date : 2024/12/9 10:52
 * @Version: 1.0
 */
public class WindPowerVoToWordTemplate {
    // 占位符替换方法
    private static void replacePlaceholderInParagraph(XWPFParagraph paragraph, Map<String, String> placeholders) {
        List<XWPFRun> runs = paragraph.getRuns();
        if (runs != null) {
            for (XWPFRun run : runs) {
                String text = run.getText(0);
                if (text != null) {
                    for (Map.Entry<String, String> entry : placeholders.entrySet()) {
                        if (text.contains("${" + entry.getKey() + "}")) {
                            text = text.replace("${" + entry.getKey() + "}", entry.getValue());
                            run.setText(text, 0);
                        }
                    }
                }
            }
        }
    }
}
